package com.example.pei.ithinklearnt.adapter;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.pei.ithinklearnt.AppApplication;
import com.example.pei.ithinklearnt.R;
import com.example.pei.ithinklearnt.adapter.base.BaseViewHolder;
import com.example.pei.ithinklearnt.adapter.base.OnRecyclerViewListener;
import com.example.pei.ithinklearnt.bean.UserInfo;
import com.example.pei.ithinklearnt.view.activity.UserInfoActivity;

import butterknife.BindView;

import static com.example.pei.ithinklearnt.utils.ImageLoaderUtil.displayImage;
import static com.example.pei.ithinklearnt.utils.ImageLoaderUtil.getPhotoImageOption;
import static com.example.pei.ithinklearnt.utils.ImageLoaderUtil.getPhotoImageOption2;

public class SearchUserHolder extends BaseViewHolder {

    @BindView(R.id.avatar)
    public ImageView avatar;
    @BindView(R.id.name)
    public TextView name;
    @BindView(R.id.btn_add)
    public Button btn_add;

    public SearchUserHolder(Context context, ViewGroup root, OnRecyclerViewListener onRecyclerViewListener) {
        super(context, root, R.layout.item_search_user,onRecyclerViewListener);
    }

    @Override
    public void bindData(Object o) {
        final UserInfo user =(UserInfo)o;
        // TODO: 2018/1/27  这里改了一点
        //ImageLoaderFactory.getLoader().loadAvator(avatar,user.getAvatar(), R.mipmap.head);
        displayImage(AppApplication.getContext(),  avatar, user.getHeadFileUrl(),getPhotoImageOption2());
        name.setText(user.getUsername());
        btn_add.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {//查看个人详情
                Bundle bundle = new Bundle();
                bundle.putSerializable("u", user);
                startActivity(UserInfoActivity.class,bundle);
            }
        });
    }
}